package jmine.tec.utils.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author takeshi
 */
public final class Iterators {

    /**
     * C'tor
     */
    private Iterators() {
        throw new IllegalStateException("Iterators cannot be instantiated");
    }

    /**
     * Coleta o restante do {@link Iterator} em uma {@link List}
     * 
     * @param <T> o tipo
     * @param iterator {@link Iterator}
     * @return {@link List}
     */
    public static <T> List<T> collectToList(Iterator<? extends T> iterator) {
        List<T> list = new ArrayList<T>();
        while (iterator.hasNext()) {
            list.add(iterator.next());
        }
        return list;
    }

}
